package com.basic.bio.chat.easy;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Description:
 * @Date: 2024-03-28 19:08
 * @Author: wz
 **/
public class Client {

    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1", 8888);
            Scanner scanner = new Scanner(System.in);
            while (true){
                String msg = scanner.next();
                OutputStream os = socket.getOutputStream();
                os.write(msg.getBytes());
                os.flush();
                socket.shutdownOutput();
                System.out.println("客户端1关闭输出流");
                InputStream is = socket.getInputStream();
                int len;
                byte[] buf = new byte[1024];
                while ((len = is.read(buf)) != -1){
                    System.out.println("服务端发来的消息："+new String(buf,0,len));
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
